<template>
  <section class="app-inner">
    <el-card class="header-card">
      <el-row type="flex" class="row-bg" justify="space-between">
        <el-col :span="18"><h2 style="margin-bottom:20px">查看巡检任务</h2></el-col>
        <el-col :span="3" style="text-align: right;"
          ><el-button type="success" @click="resetForm('ruleForm')" size="small" class="return-btn">返回</el-button>
        </el-col>
      </el-row>
      <el-form :model="ruleForm" ref="ruleForm" label-width="500px" class="demo-ruleForm">
        <el-form-item label="任务编号">
          {{ ruleForm.taskCode }}
        </el-form-item>
        <el-form-item label="任务类型">
          {{ getName(ruleForm.taskType) }}
        </el-form-item>
        <el-form-item label="任务名称">
          {{ ruleForm.taskName }}
        </el-form-item>
        <el-form-item label="巡检执行人">
          {{ ruleForm.taskOperatorUserName }}
        </el-form-item>
        <el-form-item label="计划开启巡检时间">
          {{ ruleForm.startTime }}
        </el-form-item>
        <!-- <el-form-item label="实际完成时间">
          {{ruleForm.endTime}}
        </el-form-item> -->
        <el-form-item label="处理状态">
          {{ getLable(ruleForm.taskCompleteState) }}
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="table-card">
      <h2>巡检情况反馈</h2>
      <div v-for="(item, index) in spotArray" :key="index" class="position-tab">
        <div>
          <h3>{{ index + 1 }}</h3>
          <span>{{ item.spotName }}</span>
        </div>
        <el-table
          v-if="ruleForm.taskType == 2"
          border
          :data="item.taskSpotEventRelationList"
          :key="index"
          style="width: 100%"
        >
          <el-table-column type="index" label="序号" width="50"></el-table-column>
          <el-table-column prop="taskContent" label="巡查内容"></el-table-column>
          <el-table-column prop="inputMode" label="输入模式" :formatter="entryFormatter"></el-table-column>
          <el-table-column prop="" label="是否必须反馈">是</el-table-column>
        </el-table>
      </div>
    </el-card>
  </section>
</template>

<script>
import { getTaskInfo } from './js/patrol'
import { entryMode, planTypeList } from './js/constants'
export default {
  data () {
    return {
      spotArray: [],
      openFlag: true,
      ruleForm: {
        taskCode: '',
        taskName: '',
        userName: '',
        spotCode: '',
        region: '',
        date1: '',
        date2: '',
        startTime: '',
        endTime: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
        tag: ''
      }
    }
  },
  created () {
    this.ruleForm = this.$route.query
    switch (this.ruleForm.taskCompleteState) {
      case 0:
        this.ruleForm.taskCompleteState = '待巡检'
        break
      case 1:
        this.ruleForm.taskCompleteState = '未完成'
        break
      case 2:
        this.ruleForm.taskCompleteState = '已完成'
        break
    }
    if (this.ruleForm.taskCode) {
      window.localStorage.setItem('patrolTask', JSON.stringify(this.ruleForm))
    } else {
      this.ruleForm = JSON.parse(window.localStorage.getItem('patrolTask'))
    }
    this.getSpotList()
  },
  methods: {
    entryFormatter (row, column, cellValue) {
      return this.$base.constFormatter(entryMode, cellValue)
    },
    async getSpotList () {
      let res = await getTaskInfo(this.ruleForm.taskCode)
      this.spotArray = res.data.taskSpotEventList
    },
    resetForm () {
      this.$router.push({ path: 'InspectList' })
    },
    // 获取name
    getName (val) {
      return this.$base.constFormatter(planTypeList, +val)
    },
    getLable (val) {
      // 2代表已完成，1代表未完成，0表示待巡检
      let arr = ['待巡检', '未完成', '已完成']
      return arr[+val]
    }
  }
}
</script>

<style lang="scss" scoped>
.app-inner {
  height: 100%;
  font-size: 16px;
  .header-card,
  .table-card,
  .form-card,
  .foot-card {
    margin-bottom: 10px;
    .el-form {
      .el-form-item {
        .el-input {
          width: 160px;
        }
      }
      // .createBtn {
      //   float: right;
      // }
    }
  }
  .table-card {
    .position-tab {
      div {
        margin: 10px 0;
        h3 {
          display: inline-block;
          margin-right: 10px;
        }
        .el-button {
          margin: 0 10px;
          border-radius: 15px;
        }
      }
    }
    h2 {
      margin-bottom: 16px;
    }
  }
  .form-card {
    .demo-ruleForm {
      margin: 0 auto;
    }
  }
  .foot-card {
    .btn-group {
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .el-pagination {
    text-align: center;
    display: block;
    margin: 10px auto;
  }
  .img-over {
    margin-right: 5px;
    width: 60px;
    height: 45px;
    cursor: pointer;
  }
}
</style>
